<template>
  <div>
    <Searchbar>
      <el-input style="margin-right: 10px" @change="getList" v-model="search.username" placeholder="请输入用户名"></el-input>
      <el-select style="margin-right: 10px" @change="onStatusChange" v-model="search.status" placeholder="请选择用户状态">
        <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-button @click="getList" type="primary">查询</el-button>
      <el-button @click="resetSearch" type="primary">重置</el-button>
      <el-button class="search-btn" @click="onShowCreate" type="primary" icon="el-icon-plus">新建</el-button>
    </Searchbar>
<!--    <TableBar>-->
<!--      <el-button @click="onShowCreate" type="primary" icon="el-icon-plus">新建</el-button>-->
<!--    </TableBar>-->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="username" label="用户名" ></el-table-column>
      <el-table-column prop="phone" label="手机号" ></el-table-column>
      <el-table-column prop="statusLabel" label="状态" ></el-table-column>
      <el-table-column prop="create_time" label="创建时间" ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="onShowEdit(scope.row)" size="small" type="primary">编辑</el-button>
          <!-- <el-button
            @click="onForbidden(scope.row)"
            size="small"
            :class="scope.row.status == 1 ? 'text-warning' : 'text-button'"
          >{{scope.row.status == 1 ? '封停' : '启用'}}</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next, sizes, jumper"
      @current-change="handleCurrentChange"
      @size-change=handleSizeChange
      :current-page.sync="search.page"
      :page-sizes="page_sizes"
      :page-size="search.page_size"
      :total="total"
    ></el-pagination>
    <EditAdmin @afterSubmit="getList" @onClose="onHideEdit" :obj="editRow" :show="showEdit" />
  </div>
</template>
<script>
import EditAdmin from "@/modals/EditAdmin";
import CreateFilter from "@/mixins/CreateFilter";
import showEditMixin from "@/mixins/showEditMixin";
import pageMixin from "@/mixins/pageMixin";
import blockMixin from "@/mixins/blockMixin";
import { adminModel } from "@/api/admin_models";
import Searchbar from "@/components/Searchbar";
import TableBar from "@/components/TableBar";
export default {
  mixins: [CreateFilter, showEditMixin, pageMixin, blockMixin],
  components: { EditAdmin, Searchbar, TableBar },
  data() {
    return {
      tableData: [],
      total: 0,
      search: {
        phone: null,
        status: null,
        page: 1,
        page_size: 10
      }
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    resetSearch() {
      this.search = {
        username: null,
        status: null,
      }
      this.getList() 
    },
    getList() {
      console.log("getList");
      adminModel.list(
        this.search,
        res => {
          this.total = res.total_records;
          this.tableData = res.data.map(v => {
            v.statusLabel = this.userStatusToLabel(v.user_status);
            return v;
          });
        },
        err => {
          console.log(err);
        }
      );
    }
  }
};
</script>
<style lang="scss">
</style>